package com.baidu.service.impl;

import com.baidu.model.entity.AlbumModel;
import com.baidu.model.entity.AlbumModelWithBLOBs;
import com.baidu.model.mapper.AlbumModelMapper;
import com.baidu.service.InAlbumService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.until.pagination.PaginationRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author user
 */
@Service
public class AlbumServiceImpl implements InAlbumService {

    @Autowired
    private AlbumModelMapper albumModelMapper;

    /**
     * 添加相册相关内容
     *
     * @param albumModel 添加相册的模型
     * @return 返回新建的数据
     * @throws Exception 未定义错误
     */
    @Override
    public AlbumModel createAlbumModel(AlbumModel albumModel) throws Exception {
        albumModelMapper.insertSelective(albumModel);
        return albumModel;
    }

    /**
     * 得到用户id 相关的相册信息
     *
     * @param userid 用户id
     * @return 返回id的相关的相册相关信息
     */
    @Override
    public PageInfo<AlbumModelWithBLOBs> selectByUserId(Integer userid, PaginationRequest page) {
        return PageHelper.startPage(page.getPageNumber(), page.getPageSize()).doSelectPageInfo(() -> albumModelMapper.selectAllAlbumModelByBlob(userid));
    }
}
